﻿using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;

public class DelOverInClientList
{
    [MenuItem("GameEditor/删除工程多余资源")]
    public static void DelOver()
    {
        string clientPath = PathUtil.CheckPath(PathUtil.VS_CONFIG);
        FileData clientList = new FileData();
        StringBuilder sb = new StringBuilder();
        string fullPath = Application.streamingAssetsPath + '/' + PathUtil.VS_CONFIG;
        using (FileStream fs = new FileStream(fullPath, FileMode.Open))
        {
            StreamReader sr = new StreamReader(fs);
            byte[] bytes = Encoding.Default.GetBytes(sr.ReadToEnd());
            clientList.ReadBytes(bytes);
        }
        for (int idx = 0; idx < clientList.files.Count; ++idx)
        {
            string file = clientList.files[idx];
            ResData rs = clientList.resData[idx];
            if (File.Exists(Application.streamingAssetsPath + '/' + file))
            {
                sb.Append(rs.ToString());
            }
        }
        //回写
        byte[] content = Encoding.UTF8.GetBytes(sb.ToString());
        File.WriteAllBytes(fullPath, content);
    }
}